package com.example.egghttp.retrofit.interceptor;

import com.example.egghttp.EggLog.L;
import com.example.egghttp.retrofit.encrypt.MD5;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;

public class GeneraterSign implements Interceptor {
    //    private  String gsign;
    private String ciphertext;

    @Override
    public okhttp3.Response intercept(Chain chain) throws IOException {
        Request original = chain.request();


        if (original.method().equals("POST")) {


            L.d("hcic", "original.url():" + original.url());





            ciphertext = MD5.md5(original.headers().get("access-time") + "-" + original.headers().get("access-token") + "-" + original.headers().get("access-key"));

        } else if (original.method().equals("GET")) {
            ciphertext = MD5.md5(original.headers().get("access-time") + "-" + original.headers().get("access-token") + "-" + original.headers().get("access-key"));


        }


        Request request = original.newBuilder()
//                                                  .header("Content-Type", "application/json")
//                .header("Sign", gsign)
//                .header("access-key", gsign)
                .header("access-ciphertext", ciphertext == null ? "" : ciphertext)
//                .header("AppId", "pos")
                .method(original.method(), original.body())
                .build();

        return chain.proceed(request);
    }
}
